package client

import (
	"imooc.com/crawler/engine"
	"imooc.com/crawler_distrilbuted/config"
	"imooc.com/crawler_distrilbuted/worker"
	"net/rpc"
)

func CreateProcessor(clientChan chan *rpc.Client) (engine.Processor, error)  {
	return func(request engine.Request) (engine.ParseResult, error) {

		sReq := worker.SerializeRequest(request)
		var sResult worker.ParseResult
		client := <- clientChan
		err := client.Call(config.CrawlServiceRpc, sReq, &sResult)
		if err != nil {
			return engine.ParseResult{},err
		}

		return worker.DeserializeResult(sResult),nil
	}, nil
}
